#ifndef MAINWINDOW_H
#define MAINWINDOW_H



#include "manualthread.h"
#include "beidouportobject.h"
#include "serialportsmanager.h"
#include "serialthread.h"
#include "bdsetmodelthread.h"
#include <QSerialPort>

#include <QLinkedList>
#include <QMainWindow>

class CustomCommandThread;


namespace Ui {
class MainWindow;
}

class ATCommandItem
{
public:
    QString atCommand;
    QString atName;
    QString resposeData;
    QString resposeGood;
    QString resposeBad;


    bool check;
    int result;

};

class FrameWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit FrameWindow(QWidget *parent = nullptr);
    ~FrameWindow();
    QApplication *app;

    SerialThread *serialThread;
    CustomCommandThread *customCommThread;
    ManualThread *manualThread;

    QLinkedList<QString> COMLists;

    Ui::MainWindow *getUI();

    void onSendData(QString value);
    void showReceiveData(QByteArray value);

    QLinkedList<ATCommandItem> commandList;

    QLinkedList<ATCommandItem> customCommands;

    QString  ManualCommand;
    int getUserSelect();

    int clearShow();
    // 获取串口列表
    int getCOMList();
    int getCustomCommands();
    int getManualCommand();

    void listBeidouCOMs();

    BeidouObject * beidouObject =nullptr;

    /**
     * @brief Open Beidou port and Set mode
     * @param comName, port Name
     */
    void OpenAndSetMode(QString comName);

    /**
     * @brief 北斗通信串口
     */
    QString  name_BD_COM;

    /**
     * @brief
     */
    QString  recognize_COM_Name;

    /**
     * @brief MCU serial Port
     */
    QString  name_MCU_COM;
    /**
     * @brief recognize COM of 4G module
     * @param fist
     * @return recognized COM Name
     */


    QMutex mutex_ui_update;
    QWaitCondition waitCon_ui_update;

    volatile bool beidou_is_stop = false;



  //Q_INVOKABLE
public slots:

    void onManualSendAndReceive(QString COMName, QString rev, QString  rw);
    void onReceiveResult(QString COMName, QString rev, int result);

    void slot_finished_beidou_COM(QString beidou);

    void onAutoTestEnd();

    void onReceivdBeidou(QByteArray receivArea);

    //识别4G串口
    void on_pushButtonCOMName_clicked();


    QString  recognize_4G_COM(QString fist);

    void  UI_top_message_box(QString titie,QString text);



    void on_pushButtonAutoStart_clicked();


    // 反选
    void SelectInvert_clicked();

    void on_pushButton_ManualMode_clicked();

    void on_pushButton_AutoMode_clicked();

    void onSendCustomResult(QString COMName, QString rev, int result);

    void onSendCustom(QString COMName, QString sent);
    void onTransfer_result(QStringList result);


private slots:
    void on_pushButton_manualSend_clicked();
    void on_pushButton_custom_send_clicked();
    /**
     * @brief 北斗打开
     */
    void on_pushButton_beidouCOM_clicked();
    void on_pushButton_BeidouMode_clicked();
    void on_comboBox_Mode_activated(int index);

    // 手动添加的下拉框单击响应信号处理函数
    //void on_comboBox_beidouCOM_clicked();

    void on_actionAbout_triggered();

signals:

   // void beidou_quit();

private:
    Ui::MainWindow *ui;

    int intialWindow();
    void initialManualPage();
    int loadATCommand();

    BDSetModelThread * beidouThread;

    bool manualInitial;

    QImage *img_good =nullptr;
    QImage *img_bad=nullptr;


    void setBeiDouMode(int index);
};



#endif // MAINWINDOW_H
